#include <stdio.h>
#include "studentList.h"
#include "draw.h"
#include "read.h"
#include "save.h"

int main()
{
    STUDENT *head = creat_list();
    STUDENT *node;
	FILE *fp = fopen("studentDate.xml", "r");
	read_student_data_from_file(head, fp);
	
	Menu_init();
    int opt;
    int math;
    int chinese;
    int english;
    char number[20];
    char name[20];
    char phone[20];
	while(1)
    {
		printf("请输入菜单选项:");
		scanf("%d", &opt);
		getchar();
		switch (opt)
        {
			case 1:
				//新增学生基本信息
		printf("请输入学生打基本信息");
		scanf("%s %s %s",number,name,phone);
                node = creat_node_by_basic_information(number, name, phone);
                insert_node(head, node);
				break;
			case 2:
				//显示所有学生基本信息
                Interface_basic_info();
				display_all_basic_information(head);
                Interface_basic_info2();
				break;
			case 3:
				//修改学生电话号码

		printf("请输入学生姓名 修改后打电话");
		scanf("%s %s",name,phone);
                change_phone_number(head,name,phone);
				break;
			case 4:
				//删除学生信息
		printf("请输入学生姓名");
		scanf("%s ",name);
                del_node_by_name(head, name);
				break;
			case 5:
				// 添加学生成绩
		printf("请依次输入学生姓民 语文 数学 英语成绩");
                scanf("%s %d %d %d",name,&chinese,&math,&english);
                insert_stuNode_score(head,name,chinese,math,english);
				break;
			case 6:
				// 显示所有学生成绩
                Interface_score();
				display_all_scores(head);
                Interface_score2();
				break;
			case 7:
				//查找学生基本信息
		printf("请输入学生姓名");
		scanf("%s ",name);
                node = find_node_by_name(head,name);
                Interface_basic_info();
                display_basic_information(node);
                printf("\n");
                Interface_basic_info2();
				break;
			default :
				break;
		}
		if (opt == 0)
        {
			FILE *fp = fopen("studentDate.xml", "w");
			Save_Student_Data(head, fp);
			fclose(fp);
			break;
		}
	}
    destory_list(&head);
    return 0;
}
